package org.znxs.comfriend.utils;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;

import java.io.File;
import java.io.FileOutputStream;

public class ImageUtils {

    static public String avatar = "https://img.znxs.vip/znxs/avatar_%E7%A5%9E%E9%87%8C.jpg";

    static public String saveImageToInternalStorage(Context context, int drawableResourceId, String fileName) {
        try {
            // 获取 Drawable 资源
            Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), drawableResourceId);

            // 创建文件输出流
            File directory = context.getFilesDir(); // 内部存储目录
            File file = new File(directory, fileName);
            FileOutputStream fos = new FileOutputStream(file);

            // 压缩并保存图片
            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.close();

            // 返回文件路径
            return file.getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}